﻿using UnityEngine;
using System.Collections;

public enum EGameDevMenu
{
	None,
	CharSelect1,
	CharSelect2,
	CharSelect3,
	CharSelect4,
	ShowPacketLog,
	ServerDebugOnOff,
	WakeUp,
	Continue,
	GameOver,
	SaveReplay,
	CameraTest,
	ShowFps,
	OpenDevMenu,
	PacketWaitingInfo,
	bgmVolUp,
	bgmVolDown,
	DiceColor,
	CharSelect5,
	ToggleBG,
	ToggleTileEff,
}

public class GameDevCommand : MonoBehaviour {
	
	public EGameDevMenu devMenu;

	public void Init()
	{
		if(CSceneManager.BuilderIsOn)
		{
			gameObject.GetComponentInChildren<UILabel>().text = "Off";
		}
		else
			gameObject.GetComponentInChildren<UILabel>().text = "On";
	}

	void OnClick()
	{
		if(devMenu == EGameDevMenu.CharSelect1)
			CSceneManager.manager.SetCharSelect(1);
		else if(devMenu == EGameDevMenu.CharSelect2)
			CSceneManager.manager.SetCharSelect(2);
		else if(devMenu == EGameDevMenu.CharSelect3)
			CSceneManager.manager.SetCharSelect(3);
		else if(devMenu == EGameDevMenu.CharSelect4)
			CSceneManager.manager.SetCharSelect(4);
		else if(devMenu == EGameDevMenu.CharSelect5)
			CSceneManager.manager.SetCharSelect(5);
		else if(devMenu == EGameDevMenu.ShowPacketLog)
		{
			//glog.debugIsOn = !glog.debugIsOn;
			StageManagerWrapper.manager.bShowPacketLog = !StageManagerWrapper.manager.bShowPacketLog;

		}
		else if(devMenu == EGameDevMenu.ServerDebugOnOff)
		{
			CSceneManager.BuilderIsOn = !CSceneManager.BuilderIsOn;
			if(CSceneManager.BuilderIsOn)
			{
				CSceneManager.DisableMinimapCollider(true);
				gameObject.GetComponentInChildren<UILabel>().text = "Off";
			}
			else
			{
				CSceneManager.DisableMinimapCollider(false);
				gameObject.GetComponentInChildren<UILabel>().text = "On";
			}
		}
		else if(devMenu == EGameDevMenu.WakeUp)
			CNetworkManager.Instance.SendRequest("wakeup;");
		else if(devMenu == EGameDevMenu.Continue)
		{
			CSceneManager.ContinuePlay();
		}
		else if(devMenu == EGameDevMenu.GameOver)
		{
//			if(BattleManager.Instance.bCombatHappened)
//			{
//				if(!isGameOverPressed)
//				{
//					isGameOverPressed=true;
//					StartCoroutine("CoGameOver");
//				}
//			}
//			else
				CNetworkManager.Instance.SendRequest("GameOver;");
		}
		else if(devMenu == EGameDevMenu.SaveReplay)
			CSceneManager.manager.SaveReplay();
		else if(devMenu == EGameDevMenu.CameraTest)
		{
			UIManager.Instance.OpenCamDebugPanel();
		}
		else if(devMenu == EGameDevMenu.ShowFps)
		{
			//HUDFPS c = GameObject.FindObjectOfType(typeof(HUDFPS)) as HUDFPS;
			GameObject go = GameObject.Find ("HUDFps");
			//GameObject go = c.gameObject;
			if(go!=null)
			{	
				go.GetComponent<GUIText>().enabled = !go.GetComponent<GUIText>().enabled;
					
//				if(go.activeSelf)
//					go.SetActive(false);
//				else
//					go.SetActive(true);
			}
		}
		else if(devMenu == EGameDevMenu.OpenDevMenu)
		{
			CSceneManager.ToggleDebugPanel();
		}
		else if(devMenu == EGameDevMenu.PacketWaitingInfo)
			CSceneManager.bShowPacketWaitingInfo = !CSceneManager.bShowPacketWaitingInfo;
		else if(devMenu == EGameDevMenu.bgmVolUp)
			SoundManagerCommon.Instance.BGMVolumeUp();
		else if(devMenu == EGameDevMenu.bgmVolDown)
			SoundManagerCommon.Instance.BGMVolumeDown();
		else if(devMenu == EGameDevMenu.DiceColor)
		{
			UIManager.Instance.OpenTestDiceColorPanel();
		}
		else if(devMenu == EGameDevMenu.ToggleBG)
		{
			if(BoardManager.Instance.m_bgParent!=null)
			{
				if(BoardManager.Instance.m_bgParent.activeSelf)
					BoardManager.Instance.m_bgParent.SetActive(false);
				else
					BoardManager.Instance.m_bgParent.SetActive(true);
			}
		}
		else if(devMenu== EGameDevMenu.ToggleTileEff)
		{
			foreach(GameObject goEff in BoardTile.tileElementEffectList)
			{
				if(goEff.activeSelf)
					goEff.SetActive(false);
				else
					goEff.SetActive(true);
			}
		}
		
		if(devMenu != EGameDevMenu.OpenDevMenu && devMenu != EGameDevMenu.bgmVolUp && devMenu != EGameDevMenu.bgmVolDown)
			CSceneManager.ShowDebugPanel(false);
	}

//	IEnumerator CoGameOver()
//	{
//
//	}
}
